package org.ricks.ioc;

import org.ricks.log.Logger;
import org.ricks.utils.FileUtil;
import org.ricks.utils.StrUtil;

/**
 * @author chenwei
 * @Title:
 * @Package
 * @Description:
 * @date 2021/3/815:15
 */
public class DefaultBanner implements Banner{

    public static String DEFAULT_BANNER_FILE = "banner.txt";

    private static final String[] BANNER = { "", "  .   ____          _            __ _ _",
            " /\\\\ / ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\", "( ( )\\___ | '_ | '_| | '_ \\/ _` | \\ \\ \\ \\",
            " \\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )", "  '  |____| .__|_| |_|_| |_\\__, | / / / /",
            " =========|_|==============|___/=/_/_/_/" };

    private static final String SPRING_BOOT = " :: IOC :: ";

    private static final int STRAP_LINE_SIZE = 42;

    @Override
    public void printBanner() {
        String bannerInfo = FileUtil.readFile(DEFAULT_BANNER_FILE);
        if(StrUtil.isNotBlank(bannerInfo)){
            Logger.info(bannerInfo,true);
        } else {
            StringBuilder sb = new StringBuilder();
            for (String msg : BANNER) {
                sb.append(msg).append("\n");
            }
            while (sb.length() < STRAP_LINE_SIZE -  SPRING_BOOT.length()) {
                sb.append(" ");
            }
            Logger.info(sb.toString(),true);
        }
    }

    public static void main(String[] args) {
//        DefaultBanner defaultBanner = new DefaultBanner();
//        defaultBanner.printBanner(DefaultBanner.class, Logger);
        for (String line : BANNER) {
            Logger.info(line);
        }
    }
}
